package com.fbinggun.dt.task.conditions;

import com.FBinggun.Sbox.OpenBoxEvent;
import com.fbinggun.dt.task.Task;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Box extends Conditions{
    List<String> list = new ArrayList<>();

    public Box(String id, ConfigurationSection config, Task task) {
        super(id, config, task);
        list=config.getStringList("Type");
    }
    @EventHandler
    public void openBox(OpenBoxEvent event) throws SQLException, ClassNotFoundException {
        Player player = event.getPlayer();
        if(isRun(player)){
            String id = event.getBox().getId();
            if (list == null || list.size() == 0) {
                addCount(player, 1);
            } else {
                if (list.contains(id)) {
                    addCount(player, 1);
                }
            }
        }
    }
}
